public class SingleLinkedList {
    static class ListNode {
        public int val;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;

        }
        public ListNode(){

        };
    }

    public ListNode head;
    public ListNode partition(int x){
        ListNode cur=head;
        ListNode bs=null;
        ListNode be=null;
        ListNode as=null;
        ListNode ae=null;

        while (cur!=null){
            if(cur.val<x){
                if(bs==null){//第一次插入
                    bs=be=cur;

                }else {
                    be.next=cur;
                    be=cur;
                }


            }else {
                if(as==null){
                    as=ae=cur;

                }
                ae.next=cur;
                ae=cur;

            }
            cur=cur.next;
        }
        if(bs==null){
            return as;
        }
        be.next=as;
        if(as!=null){
            ae=null;
        }
        return bs;
    }
}

